<!--
 * Description: 专案列表查看主页面
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Dongxu.Ni
 * Date: 2020/03/31 07:26
-->

<template>
  <BaseWrap>
    <!-- 查询条件 -->
    <BaseFunc
      :is-requesting="isRequesting"
      :query-form="queryForm"
      :visible.sync="advanceOptionDrawer"
      @query="query"
    >
      <!--抽屉内部查询表单-->
      <template>
        <el-form class="g-advance-drawer-form" label-width="100px" :model="queryForm" size="mini">
          <el-row>
            <!--专案编号-->
            <el-col :span="6">
              <el-form-item :label="$t('ProjectView.projectId')">
                <el-input v-model="queryForm.projectId" clearable />
              </el-form-item>
            </el-col>

            <!--专案名称-->
            <el-col :span="6">
              <el-form-item :label="$t('ProjectView.projectName')">
                <el-input v-model="queryForm.projectName" clearable />
              </el-form-item>
            </el-col>

            <!--系列-->
            <el-col :span="6">
              <el-form-item :label="$t('ProjectView.series')">
                <el-input v-model="queryForm.series" clearable />
              </el-form-item>
            </el-col>

            <!--PM-->
            <el-col :span="6">
              <el-form-item :label="$t('ProjectView.pm')">
                <el-input v-model="queryForm.pm" clearable />
              </el-form-item>
            </el-col>

            <!--PBM负责人-->
            <el-col :span="6">
              <el-form-item :label="$t('ProjectView.pbmOwner')">
                <el-select
                  v-model="queryForm.pbmOwner"
                  clearable
                  filterable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['user/getPbmUserSimpleCollects']"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId"
                  >
                    <span style="float: left;">{{ item.userName }}</span>
                    <span style="float: right; color: #b4b4b4; font-size: 12px">
                      {{ item.gcmFunction + ' ' + item.team }}
                    </span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <!--ME负责人-->
            <el-col :span="6">
              <el-form-item :label="$t('ProjectView.meOwner')">
                <el-select
                  v-model="queryForm.meOwner"
                  clearable
                  filterable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['user/getMEGcmUserSimpleCollects']"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId"
                  >
                    <span style="float: left;">{{ item.userName }}</span>
                    <span style="float: right; color: #b4b4b4; font-size: 12px">
                      {{ item.gcmFunction + ' ' + item.team }}
                    </span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <!--EE负责人-->
            <el-col :span="6">
              <el-form-item :label="$t('ProjectView.eeOwner')">
                <el-select
                  v-model="queryForm.eeOwner"
                  clearable
                  filterable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['user/getEEGcmUserSimpleCollects']"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId"
                  >
                    <span style="float: left;">{{ item.userName }}</span>
                    <span style="float: right; color: #b4b4b4; font-size: 12px">
                      {{ item.gcmFunction + ' ' + item.team }}
                    </span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <!--PKG负责人-->
            <el-col :span="6">
              <el-form-item :label="$t('ProjectView.pkgOwner')">
                <el-select
                  v-model="queryForm.pkgOwner"
                  clearable
                  filterable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['user/getPKGGcmUserSimpleCollects']"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId"
                  >
                    <span style="float: left;">{{ item.userName }}</span>
                    <span style="float: right; color: #b4b4b4; font-size: 12px">
                      {{ item.gcmFunction + ' ' + item.team }}
                    </span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </template>
    </BaseFunc>

    <!--专案数据表格-->
    <BaseTable
      :is-requesting="isRequesting"
      :page-number.sync="pageNumber"
      :page-size.sync="pageSize"
      :table-data="tableData"
      :total="total"
      @query="query"
    >
      <!-- 左浮动 -->
      <template slot="header">
        <!--序号列-->
        <el-table-column align="center" fixed :label="$t('table.NO')" min-width="50px">
          <template slot-scope="scope">
            <span>{{ scope.$index + 1 }}</span>
          </template>
        </el-table-column>
      </template>

      <template>
        <!--专案编号列-->
        <el-table-column
          align="center"
          :label="$t('ProjectView.projectId')"
          min-width="150px"
          prop="projectId"
          sortable
        />
        <!--专案名称列-->
        <el-table-column
          align="center"
          :label="$t('ProjectView.projectName')"
          min-width="200px"
          prop="projectName"
          show-overflow-tooltip
          sortable
        />
        <!--bu类型列-->
        <el-table-column
          align="center"
          :label="$t('ProjectView.bu')"
          min-width="100px"
          prop="bu"
          sortable
        />
        <!--系列列-->
        <el-table-column
          align="center"
          :label="$t('ProjectView.series')"
          min-width="120px"
          prop="series"
          show-overflow-tooltip
          sortable
        />
        <!--专案PM列-->
        <el-table-column
          align="center"
          :label="$t('ProjectView.pm')"
          min-width="120px"
          prop="pm"
          sortable
        />
        <!--专案PBM负责人列-->
        <el-table-column align="center" :label="$t('ProjectView.pbmOwner')" min-width="100px">
          <template slot-scope="scope">
            <span>
              {{ $store.getters['user/getUserNameById'](scope.row.pbmOwner) || $t('result.none') }}
            </span>
          </template>
        </el-table-column>
        <!--专案ME负责人列-->
        <el-table-column align="center" :label="$t('ProjectView.meOwner')" min-width="100px">
          <template slot-scope="scope">
            <span>
              {{ $store.getters['user/getUserNameById'](scope.row.meOwner) || $t('result.none') }}
            </span>
          </template>
        </el-table-column>
        <!--专案EE负责人列-->
        <el-table-column align="center" :label="$t('ProjectView.eeOwner')" min-width="100px">
          <template slot-scope="scope">
            <span>
              {{ $store.getters['user/getUserNameById'](scope.row.eeOwner) || $t('result.none') }}
            </span>
          </template>
        </el-table-column>
        <!--专案PKG负责人列-->
        <el-table-column align="center" :label="$t('ProjectView.pkgOwner')" min-width="100px">
          <template slot-scope="scope">
            <span>
              {{ $store.getters['user/getUserNameById'](scope.row.pkgOwner) || $t('result.none') }}
            </span>
          </template>
        </el-table-column>
        <!--创建人列-->
        <el-table-column align="center" :label="$t('ProjectView.createUser')" min-width="100px">
          <template slot-scope="scope">
            <span>
              {{
                $store.getters['user/getUserNameById'](scope.row.createUser) || $t('result.unknown')
              }}
            </span>
          </template>
        </el-table-column>
        <!--创建时间列-->
        <el-table-column
          align="center"
          :label="$t('ProjectView.createTime')"
          min-width="140px"
          prop="createTime"
        />
        <!--修改人列-->
        <el-table-column align="center" :label="$t('ProjectView.modifyUser')" min-width="100px">
          <template slot-scope="scope">
            <span>
              {{
                $store.getters['user/getUserNameById'](scope.row.modifyUser) || $t('result.unknown')
              }}
            </span>
          </template>
        </el-table-column>
        <!--修改时间列-->
        <el-table-column
          align="center"
          :label="$t('ProjectView.modifyTime')"
          min-width="140px"
          prop="modifyTime"
        />
      </template>

      <!-- 右浮动 -->
      <template slot="end">
        <!--是否已分配列-->
        <el-table-column
          align="center"
          fixed="right"
          :label="$t('ProjectView.isAssigned')"
          min-width="100px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.isAssigned" class="tag-green">{{ '已分配' }}</span>
            <span v-else class="tag-red">{{ '未分配' }}</span>
          </template>
        </el-table-column>

        <!--操作列-->
        <el-table-column align="center" fixed="right" :label="$t('table.operate')" min-width="80px">
          <template slot-scope="scope">
            <el-button
              v-if="$hasPer('view')"
              size="mini"
              type="text"
              @click="rowView(scope.$index, scope.row)"
            >
              <i class="el-icon-view el-icon--right"></i>
              {{ $t('button.view') }}
            </el-button>
          </template>
        </el-table-column>
      </template>
    </BaseTable>

    <!--查看对话框-->
    <el-dialog
      v-if="viewDialogVisible"
      :append-to-body="true"
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :title="$t('dialog.view')"
      :visible.sync="viewDialogVisible"
      width="70%"
    >
      <project-data-local-view :input-data="currentEditRow" @cancel="viewDialogVisible = false" />
    </el-dialog>
  </BaseWrap>
</template>

<script>
import { projectPageList } from '../../../api/quote/project'
import ProjectDataLocalView from './components/ProjectDataLocalView'

export default {
  name: 'ProjectView',
  components: { ProjectDataLocalView },
  props: {},
  data() {
    return {
      // 正在查询
      isRequesting: false,
      // 高级查询选项抽屉弹出标识
      advanceOptionDrawer: false,
      // 页码
      pageNumber: 1,
      // 页展示行数
      pageSize: 10,
      // 总行数
      total: 0,
      // 表格数据
      tableData: [],
      // 查询表单对象
      queryForm: {
        projectId: '',
        projectName: '',
        projectDesc: '',
        pm: '',
        series: '',
        type: '',
        bu: '',
        pbmOwner: '',
        meOwner: '',
        eeOwner: '',
        pkgOwner: '',
        isAssigned: '',
        createPost: '',
        createUser: '',
        createTime: '',
        modifyPost: '',
        modifyUser: '',
        modifyTime: ''
      },
      // 查看对话框可见标识
      viewDialogVisible: false,
      // 当前编辑行的数据
      currentEditRow: {}
    }
  },
  computed: {},
  watch: {},
  created() {
    this.pageDataInit()
  },
  mounted() {},
  methods: {
    /* 页面数据初始化*/
    pageDataInit() {
      this.query()
    },
    /* 查询表格数据*/
    async query() {
      try {
        this.isRequesting = true
        this.advanceOptionDrawer = false
        const res = await projectPageList({
          pageSize: this.pageSize,
          pageNumber: this.pageNumber,
          pageCondition: this.queryForm
        })
        this.tableData = res.data.list
        this.total = res.data.total
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    rowView(index, row) {
      this.currentEditRow = row
      this.viewDialogVisible = true
    }
  }
}
</script>

<style lang="scss" scoped></style>
